package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.bean.MyPageOld;
import com.serkol.ams.entity.UsersAddress;
import com.serkol.ams.mapper.UsersAddressMapper;
import com.serkol.ams.service.UsersAddressService;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* @author pingan
* @description 针对表【users_address】的数据库操作Service实现
* @createDate 2022-09-16 19:40:18
*/
@Service
public class UsersAddressServiceImpl extends ServiceImpl<UsersAddressMapper, UsersAddress>
    implements UsersAddressService{

    @Override
    public boolean byDelete(long id) {
        int i = this.baseMapper.deleteById(id);
        return (i != 0);
    }

    @Override
    public MyPageOld findByList(int pageSize, int current, Long userId) {

        MyLambdaQueryWrapper<UsersAddress> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(UsersAddress::getId, UsersAddress::getAddress,UsersAddress::getName,UsersAddress::isMoren)
                        .select(UsersAddress::getAddressInfo).as("addressInfo")
                        .select(UsersAddress::getAddressName).as("addressName")
                        .select(UsersAddress::getAddress).as("address")
                        .select(UsersAddress::getLongitude).as("longitude")
                        .select(UsersAddress::getLatitude).as("latitude")
                        .select(UsersAddress::getPhoneNumber).as("phoneNumber")
                        .select(UsersAddress::getPostNumber).as("postNumber");

if(userId>0){
    queryWrapper.eq(UsersAddress::getUserId, userId);
}
        queryWrapper.orderByDesc(UsersAddress::getId);
        Page<Map<String, Object>> page = new Page<>(current, pageSize);
        Page<Map<String, Object>> mapPage = this.baseMapper.selectMapsPage(page, queryWrapper);
        return MyPageOld.parsePage(mapPage);
    }
    }






